package com.leyou.item.comsume;

import com.leyou.item.service.CategoryService;
import com.leyou.item.entity.Category;
import com.leyou.pojo.dto.CategoryDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryComsume {

    @Autowired
    private CategoryService categoryService;

    //按id查询单个分类信息
    @GetMapping("/{id}")
    public ResponseEntity<CategoryDTO> findCategoryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(categoryService.findCategoryById(id));
    }

    //按id查询多个分类信息
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> findCategoryByIds(@RequestParam("ids")List<Long> ids) {
        return ResponseEntity.ok(categoryService.findCategoryByIds(ids));
    }

    //根据父类目id，查询子类目的集合
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> findCategoryByParentId(Long pid) {
        return ResponseEntity.ok(categoryService.findCategoryByParentId(pid));
    }

    //根据品牌id，查询商品分类的集合
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> findCategoryByBrandId(Long id) {
        return ResponseEntity.ok(categoryService.findCategoryByBrandId(id));
    }
}
